local cuchou = fk.CreateSkill({
    name = "sj4__cuchou",
    tags = {Skill.Compulsory},
  })
  
  Fk:loadTranslationTable{
    ["sj4__cuchou"] = "粗筹",
    [":sj4__cuchou"] = "<b>锁定技</b>，结束阶段，若<a href='zhongyangqu_js'>中央区</a>的锦囊牌张数不大于1/为2或3/不小于4，你视为使用【无中生有】/【过河拆桥】/【决斗】。然后你执行满足你体力值的另一项。",
  
    ["@sj4__cuchou-turn"] = "粗筹",
  
    ["$sj4__cuchou1"] = "方策精详，有备无患。",
    ["$sj4__cuchou2"] = "精兵据敌，策守如山。",
  }

  cuchou:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(cuchou.name) and target == player and player.phase == Player.Finish
    end,
    on_cost = function (self, event, target, player, data)
      local all = {"ex_nihilo","dismantlement","duel"}
      local getnum = function(n)
        if n<2 then return 1
        elseif n>3 then return 3 end
        return 2
      end
      local names = {all[getnum(player:getMark("@sj4__cuchou-turn"))]}
      table.insertIfNeed(names,all[getnum(player.hp)])
      names = table.filter(names,function(n)
        return #Fk:cloneCard(n):getAvailableTargets(player) > 0
      end)
      if #names > 0 then
        event:setCostData(self,{names = names})
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      for _, n in ipairs(event:getCostData(self).names) do
        if n == "ex_nihilo" then
          player.room:useCard{
            from = player,
            tos = {player},
            card = Fk:cloneCard(n),
          }
        else
          player.room:askToUseVirtualCard(player,{
            name = n,
            skill_name = cuchou.name,
            cancelable = false,
          })
        end
      end
    end,
  })

  cuchou:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(cuchou.name, true) and player.phase ~= Player.NotActive then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if table.contains(player.room.discard_pile, info.cardId) then
              return true
            end
          end
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DiscardPile and not table.contains(player.room.discard_pile, info.cardId) then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local ids = player:getTableMark("sj4__cuchou-turn")
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(room.discard_pile, info.cardId) then
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.DiscardPile and not table.contains(room.discard_pile, info.cardId) then
          table.removeOne(ids, info.cardId)
        end
      end
    end
    room:setPlayerMark(player, "sj4__cuchou-turn", ids)
    room:setPlayerMark(player, "@sj4__cuchou-turn",#table.filter(ids,function (id)
      return Fk:getCardById(id).type == Card.TypeTrick
    end))
  end,
  })

  return cuchou